package cn.sinata.wanglin.village.activity;

import android.Manifest;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.baidu.mapapi.search.geocode.GeoCodeOption;
import com.baidu.mapapi.search.geocode.GeoCodeResult;
import com.baidu.mapapi.search.geocode.GeoCoder;
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
import com.facebook.drawee.view.SimpleDraweeView;
import com.hyphenate.easeui.utils.EaseSmileUtils;
import com.xilada.xldutils.adapter.BaseRecyclerAdapter;
import com.xilada.xldutils.adapter.HFRecyclerAdapter;
import com.xilada.xldutils.adapter.util.ViewHolder;
import com.xilada.xldutils.utils.ActivityUtil;
import com.xilada.xldutils.utils.PermissionManager;
import com.xilada.xldutils.utils.SharedPreferencesUtils;
import com.xilada.xldutils.utils.TimeUtils;
import com.xilada.xldutils.utils.Utils;
import com.xilada.xldutils.view.TwoTextLinearView;

import java.util.ArrayList;

import cn.sinata.wanglin.MyApplication;
import cn.sinata.wanglin.R;
import cn.sinata.wanglin.commonutils.Constant;
import cn.sinata.wanglin.mine.activity.SignupUserForMyselfListActivity;
import cn.sinata.wanglin.model.ActiveDetails;
import cn.sinata.wanglin.model.CommentBean;
import cn.sinata.wanglin.model.UserListBean;
import cn.sinata.wanglin.net.HttpManager;
import cn.sinata.wanglin.net.model.util.ResultDataSubscriber;
import cn.sinata.wanglin.utils.BdNaviMapUtil;
import cn.sinata.wanglin.utils.CallBack;
import cn.sinata.wanglin.utils.ExpUtils;
import cn.sinata.wanglin.utils.RecyclerListWithFramLayoutActivity;
import cn.sinata.wanglin.utils.RelativeDateFormat;
import cn.sinata.wanglin.utils.ShareConfig;
import cn.sinata.wanglin.utils.ShareUtils;
import cn.sinata.wanglin.utils.StringToUtils;

public class ActivedetailActivity extends RecyclerListWithFramLayoutActivity {
    private ImageView iv_gotonav;//导航
    private TextView tv_callphone;//拉起打电话
    private TextView tv_callcomment;//拉起评论
    private TextView tv_signup;//拉起报名
    private SimpleDraweeView iv_active;//活动图片
    private TextView tv_title;//活动标题
    private TwoTextLinearView ttlv_seenum_and_time;//浏览量和发布时间
    private TwoTextLinearView ttlv_start_to_stop_time;//活动开始到结束的时间
    private TextView tv_address;//活动地址
    private TextView tv_addressdetail;//活动详细地址

    private TextView tv_attend_and_all;//活动参与的人和总共的人
    private TextView tv_money;//活动价格
    private SimpleDraweeView iv_headview;//头像
    private TextView tv_username;//用户名
    private TextView tv_industry;//行业
    private TextView tv_lable;//归属标签
    private TextView tv_sexoldaddress;//性别年龄小区
    private TextView  tv_addfriend;//添加好友
    private TextView  tv_content;//内容
    private TwoTextLinearView  ttlv_havejoin;//已经参加的人员
    private TextView  tv_comment;//评论
    private RecyclerView rv_showjoinpeople ;//显示参与人头像的list
    private ArrayList<UserListBean> userListBeens=new ArrayList<>();
    private BaseRecyclerAdapter showUserListAdapter;
    private HFRecyclerAdapter showCommentAdapter;
    private ArrayList<CommentBean> showCommentdatas=new ArrayList<CommentBean>();
    private String  id=null;//内容id
    private String friendID=null;
    private String userid=null;
    private int pageNo = 0;
    private String phone=null;
    private String addressdetail=null;
    private TextView  tv_signupdetails;//to报名详情
    @Override
    protected RecyclerView.Adapter setAdapter() {
        if(showCommentAdapter==null){
            showCommentAdapter=new HFRecyclerAdapter<CommentBean>(showCommentdatas,R.layout.item_commentlist) {
                @Override
                public void onBind(final int position, final CommentBean data, ViewHolder holder) {
                    if(!TextUtils.isEmpty(data.getIsanonymity())){
                        if("1".equals(data.getIsanonymity())){
                            ((SimpleDraweeView) holder.bind(R.id.iv_headview)).setImageURI(Uri.parse("res://mipmap/"+R.mipmap.ic_isanonymity));
                        }else{
                            ((SimpleDraweeView) holder.bind(R.id.iv_headview)).setImageURI(data.getHeadUrl());
                        }
                    }else{
                        ((SimpleDraweeView) holder.bind(R.id.iv_headview)).setImageURI(data.getHeadUrl());
                    }
                    holder.bind(R.id.iv_headview).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if("1".equals(data.getIsanonymity())){
                                return;
                            }
                            ActivityUtil.create(mContext).go(AllUserInfoActivity.class).put("friendID",data.getUserID())
                                    .start();

                        }
                    });

                    if(!TextUtils.isEmpty(data.getUserName())){
                        holder.setText(R.id.tv_username,data.getUserName());
                    }else{
                        holder.setText(R.id.tv_username,Constant.DEFULT_NICKNAME);
                    }
                    if(!TextUtils.isEmpty(""+data.getCreateDate())){
                        holder.setText(R.id.tv_time,TimeUtils.getMilliTimeYMD(data.getCreateDate()));
                    }else{
                        holder.setText(R.id.tv_time,"暂无时间");
                    }

                    if (!TextUtils.isEmpty(data.getContent())) {
                        //回复类型（0评论文章,1回复评论）
                        if("1".equals(data.getType())){
                            String commentPerson=data.getParentName()+":";
                            String allcomment="回复"+commentPerson+data.getContent();
                            SpannableStringBuilder builder = new SpannableStringBuilder(allcomment);
                            ForegroundColorSpan blueSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_15));
                            ForegroundColorSpan blackSpan = new ForegroundColorSpan(getResources().getColor(R.color.commentColor));
                            builder.setSpan(blackSpan,0,2, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                            builder.setSpan(blueSpan,2,2+commentPerson.length(),Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                            builder.setSpan(blackSpan,2+commentPerson.length(),allcomment.length(),Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//                            ((TextView) holder.bind(R.id.tv_content)).setText(builder);
                            Spannable span = EaseSmileUtils.getSmiledText(mContext,builder);
                            ((TextView)holder.bind(R.id.tv_content)).setText(span, TextView.BufferType.SPANNABLE);
                        }else{
                            Spannable span = EaseSmileUtils.getSmiledText(mContext,data.getContent());
                            ((TextView)holder.bind(R.id.tv_content)).setText(span, TextView.BufferType.SPANNABLE);
                        }
                    } else {
                        holder.setText(R.id.tv_content, "暂无内容");
                    }
                }
            };
            showCommentAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    ActivityUtil.create(mContext)
                            .go(EditCommentOtherActivity.class)
                            .put("id", id)
                            .put("toUser", showCommentdatas.get(position).getUserID())
                            .put("externalType", "D")
                            .put("commentId", showCommentdatas.get(position).getId())
                            .put("type",1)
                            .put("commentUsername", showCommentdatas.get(position).getUserName())
                            .startForResult(12);
                }
            });
            View headerView = LayoutInflater.from(this).inflate(R.layout.header_activedetail,null);
            ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            headerView.setLayoutParams(params);
            showCommentAdapter.setHeaderView(headerView);
            iv_active= (SimpleDraweeView) headerView.findViewById(R.id.iv_active);//活动图片
            tv_title= (TextView) headerView.findViewById(R.id.tv_title);//活动标题
            ttlv_seenum_and_time= (TwoTextLinearView) headerView.findViewById(R.id.ttlv_seenum_and_time);//浏览量和发布时间
            ttlv_start_to_stop_time= (TwoTextLinearView) headerView.findViewById(R.id.ttlv_start_to_stop_time);//活动开始到结束时间
            tv_address= (TextView) headerView.findViewById(R.id.tv_address);//活动地址
            tv_addressdetail= (TextView) headerView.findViewById(R.id.tv_addressdetail);//活动xiangxi地址
            tv_attend_and_all= (TextView) headerView.findViewById(R.id.tv_attend_and_all);//活动参与的人和总共的人
            tv_money= (TextView) headerView.findViewById(R.id.tv_money);//活动价格
            rv_showjoinpeople= (RecyclerView) headerView.findViewById(R.id.rv_showjoinpeople);//显示参加人员头像的list
            iv_headview= (SimpleDraweeView) headerView.findViewById(R.id.iv_headview);//头像
            tv_username= (TextView) headerView.findViewById(R.id.tv_username);//用户名
            tv_industry= (TextView) headerView.findViewById(R.id.tv_industry);//行业
            tv_lable= (TextView) headerView.findViewById(R.id.tv_lable);//归属标签
            tv_sexoldaddress= (TextView) headerView.findViewById(R.id.tv_sexoldaddress);//性别年龄小区
            tv_addfriend= (TextView) headerView.findViewById(R.id.tv_addfriend);//添加好友
            tv_content= (TextView) headerView.findViewById(R.id.tv_content);//内容
            ttlv_havejoin= (TwoTextLinearView) headerView.findViewById(R.id.ttlv_havejoin);//已经参加的人员和总共人数
            tv_comment= (TextView) headerView.findViewById(R.id.tv_comment);//评论
            iv_gotonav = (ImageView) headerView.findViewById(R.id.iv_gotonav);//拉起导航
            rv_showjoinpeople.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
            showUserListAdapter=new BaseRecyclerAdapter<UserListBean>(userListBeens,R.layout.item_userlist) {
                @Override
                public void onBind(final int position, final UserListBean data, ViewHolder holder) {
                    ((SimpleDraweeView) holder.bind(R.id.iv_showphoto)).setImageURI(data.getHeadUrl());
                    holder.setText(R.id.tv_username,data.getName());
                    if(!TextUtils.isEmpty(data.getName())){
                        holder.setText(R.id.tv_username,data.getName());
                    }else{
                        holder.setText(R.id.tv_username,Constant.DEFULT_NICKNAME);
                    }
                }
            };
            rv_showjoinpeople.setAdapter(showUserListAdapter);
            ttlv_havejoin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ActivityUtil.create(mContext).go(SignupUserListActivity.class).put("activityID",id)
                            .start();
                }
            });
            iv_headview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (TextUtils.isEmpty(friendID)) {
                        return;
                    }
                    ActivityUtil.create(mContext).go(AllUserInfoActivity.class).put("friendID",friendID)
                            .start();
                }
            });
            iv_gotonav.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(TextUtils.isEmpty(addressdetail)){
                        showToast("拉起导航失败！");
                        return;
                    }
                    GeoCoder mSearch= GeoCoder.newInstance();
                    GeoCodeOption mGeoCodeOption=new GeoCodeOption();
                    mGeoCodeOption.address(addressdetail);
                    mGeoCodeOption.city("全国");
                    mSearch.geocode(mGeoCodeOption);
                    mSearch.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {
                        @Override
                        public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) {
                            Utils.systemErr("--geoCodeResult--"+geoCodeResult.toString());
                           if( geoCodeResult.getLocation()!=null){
                               showDialog("跳转中...");
                               BdNaviMapUtil.routeplanToNavi(ActivedetailActivity.this, MyApplication.lng, MyApplication.lat, geoCodeResult.getLocation().longitude,geoCodeResult.getLocation().latitude, new CallBack() {
                                   @Override
                                   public void onResult(int recode, String data, String desc) {
                                dismissDialog();
                                   }
                               });
                           }

                        }

                        @Override
                        public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {

                        }
                    });

                }
            });
        }

        return showCommentAdapter;
    }
    @Override
    protected void initView() {
        super.initView();
        setTitle("活动详情");
        userid=SharedPreferencesUtils.getString(Constant.SP_USERID);
        id=getIntent().getStringExtra("id");
        addRightButton(R.mipmap.ic_shareto, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String url= ShareConfig.shareToApp("3",id);
                ShareUtils.share(ActivedetailActivity.this,""+tv_content.getText().toString(),"开心网邻",url);
            }
        });
        showDialog();
        getData();

    }
    /**
     * 初始化底部布局，自己发布活动详情
     */
    private void initBottomViewForMyself() {
        View flView = LayoutInflater.from(this).inflate(R.layout.bottom_active_myslfe,null);
        tv_signupdetails= (TextView) flView.findViewById(R.id.tv_signupdetails);
        tv_signupdetails.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ActivityUtil.create(mContext).go(SignupUserForMyselfListActivity.class).put("activityID",id)
                        .start();
            }
        });
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.gravity= Gravity.BOTTOM;
        getFl_prent_list().addView(flView,params);
    }
/**
 * 初始化底部布局，他人活动详情
 */
    private void initBottomViewForOther() {
        View flView = LayoutInflater.from(this).inflate(R.layout.bottom_active,null);
        tv_callphone= (TextView) flView.findViewById(R.id.tv_callphone);
        tv_callcomment= (TextView) flView.findViewById(R.id.tv_callcomment);
        tv_signup= (TextView) flView.findViewById(R.id.tv_signup);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.gravity= Gravity.BOTTOM;
        getFl_prent_list().addView(flView,params);
        tv_signup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ActivityUtil.create(mContext).go(ApplyActiveActivity.class).put("activityId",id)
                        .startForResult(3);
            }
        });
        tv_callphone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(phone!=null){
                    boolean hasPermission = PermissionManager.request(ActivedetailActivity.this, Manifest.permission.CALL_PHONE,"使用您的手机拨打电话",21);
                    if(hasPermission){
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_CALL);
                        intent.setData(Uri.parse("tel:" + phone));
                        //开启系统拨号器
                        startActivity(intent);
                    }
                }else {
                    showToast("获取活动电话号码失败！");
                }

            }
        });
        tv_callcomment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(!TextUtils.isEmpty(friendID)){
                    ActivityUtil.create(mContext)
                            .go(EditCommentOtherActivity.class)
                            .put("id",id)
                            .put("toUser",friendID)
                            .put("externalType","D")
                            .startForResult(12);
                }else {
                    showToast("拉取评论失败！");
                }
            }
        });
    }

    private void getData(){
        String userid= SharedPreferencesUtils.getString(Constant.SP_USERID);
        HttpManager.getActiveDetail(userid,id,pageNo).subscribe(new ResultDataSubscriber<ActiveDetails>(this) {
            @Override
            public void onSuccess(String msg, ActiveDetails mActiveDetails) {
                mSwipeRefreshLayout.setRefreshing(false);
                setData(mActiveDetails);

            }
        });
    }
    private void setData(ActiveDetails data){
        if(TextUtils.isEmpty(friendID)){
            if(userid.equals(data.getUserId())){
                initBottomViewForMyself();
            }else{
                initBottomViewForOther();
            }
        }
        phone= data.getPhone();
        friendID=data.getUserId();
        if(!TextUtils.isEmpty(data.getPoster())){
            iv_active.setImageURI(data.getPoster());//活动图片
            iv_active.setVisibility(View.VISIBLE);//活动图片
        }else{
            iv_active.setVisibility(View.GONE);//活动图片
        }
        if(!TextUtils.isEmpty(data.getTitle())){
            tv_title.setText(data.getTitle());//标题
        }else{
            tv_title.setText("暂无活动标题");//标题
        }
        if(!TextUtils.isEmpty(data.getBrowses())){
            ttlv_seenum_and_time.setLeftText(data.getBrowses());//浏览量

        }else{
            ttlv_seenum_and_time.setLeftText("0");//浏览量
        }
        ttlv_seenum_and_time.setRightText(TimeUtils.getCurrentTimeMMDD(data.getCreateDate()));//发布时间
        if(!TextUtils.isEmpty(""+data.getStarDate())){
            ttlv_start_to_stop_time.setLeftText(RelativeDateFormat.getCurrentTimeMMDDHHMM(data.getStarDate())+"至"+RelativeDateFormat.getCurrentTimeMMDDHHMM(data.getEndDate()));

        }else{
            ttlv_start_to_stop_time.setLeftText("暂无时间");
        }
        if(!TextUtils.isEmpty(data.getAddress())){
            String[] str=data.getAddress().split("\\|");
            if(str!=null&&str.length==2){
                tv_address.setText(str[0].toString());
                addressdetail=str[1].toString();
                tv_addressdetail.setText(str[1].toString());
            }
        }else{
            tv_address.setText("暂无活动地址");//活动地址
        }
        String attend=null;
        if(!TextUtils.isEmpty(data.getAttend())){
            attend=data.getAttend();//参与人数
        }else{
            attend="0";//参与人数
        }
        if(!userid.equals(friendID)) {
            //首先判断时间
            if(RelativeDateFormat.isLowerCurrent(data.getStarDate())){
                //当前时间已经大于开始时间了。、说明活动开始或者结束了
                if(RelativeDateFormat.isLowerCurrent(data.getEndDate())){
                    tv_signup.setText("已经结束");
                    tv_signup.setBackgroundColor(getResources().getColor(R.color.disableColor));
                    tv_signup.setEnabled(false);
                }else{
                    tv_signup.setText("已经开始");
                    tv_signup.setBackgroundColor(getResources().getColor(R.color.disableColor));
                    tv_signup.setEnabled(false);
                }

            }else{
                if ("-1".equals(data.getPeople())) {
                    //不限人数
                    tv_signup.setText("我要报名");
                    tv_signup.setBackgroundColor(getResources().getColor(R.color.app_theme_color));
                    tv_signup.setEnabled(true);
                }else{
                    //判断报名与限制人数
                    int haveNum=  Integer.parseInt(attend);
                    int allNum=   Integer.parseInt(data.getPeople());
                    if(haveNum<allNum){
                        tv_signup.setText("我要报名");
                        tv_signup.setBackgroundColor(getResources().getColor(R.color.app_theme_color));
                        tv_signup.setEnabled(true);
                    }else{
                        tv_signup.setText("已经报满");
                        tv_signup.setBackgroundColor(getResources().getColor(R.color.disableColor));
                        tv_signup.setEnabled(false);
                    }
                }
            }

        }
        String allAttendStr="已报名（"+attend+"）";
        SpannableStringBuilder builder = new SpannableStringBuilder(allAttendStr);
        ForegroundColorSpan mSpan = new ForegroundColorSpan(getResources().getColor(R.color.app_theme_color));
        builder.setSpan(mSpan,3,allAttendStr.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        ttlv_havejoin.setLeftText(builder);

        if(!TextUtils.isEmpty(data.getPeople())&&!"-1".equals(data.getPeople())){
            String temp="已报名"+attend+"人/限"+data.getPeople()+"人报名";
            SpannableStringBuilder builderTemp= new SpannableStringBuilder(temp);
            ForegroundColorSpan mSpanAttend = new ForegroundColorSpan(getResources().getColor(R.color.app_theme_color));
            ForegroundColorSpan mSpanAttendHit = new ForegroundColorSpan(getResources().getColor(R.color.textColor99));
            builderTemp.setSpan(mSpanAttend,3,3+attend.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            builderTemp.setSpan(mSpanAttendHit,4+attend.length(),temp.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            builderTemp.setSpan(new AbsoluteSizeSpan(12,true),4+attend.length(),temp.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            tv_attend_and_all.setText(builderTemp);
        }else{
            String temp="已报名"+attend+"人/不限报名人数";
            SpannableStringBuilder builderTemp= new SpannableStringBuilder(temp);
            ForegroundColorSpan mSpanAttend = new ForegroundColorSpan(getResources().getColor(R.color.app_theme_color));
            ForegroundColorSpan mSpanAttendHit = new ForegroundColorSpan(getResources().getColor(R.color.textColor99));
            builderTemp.setSpan(mSpanAttend,3,3+attend.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            builderTemp.setSpan(mSpanAttendHit,4+attend.length(),temp.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            builderTemp.setSpan(new AbsoluteSizeSpan(12,true),4+attend.length(),temp.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            tv_attend_and_all.setText(builderTemp);//活动地址
        }


        if(!TextUtils.isEmpty(data.getExes())&&!"0".equals(data.getExes())){
            tv_money.setText(data.getExes()+"元");//价格
        }else{
            tv_money.setText("免费");//价格
        }
        iv_headview.setImageURI(data.getHeadUrl());//头像
        if(!TextUtils.isEmpty(data.getName())){
            tv_username.setText(data.getName());//用户名
        }else{
            tv_username.setText(Constant.DEFULT_NICKNAME);//用户名
        }
        switch (ExpUtils.getExpValue(data.getExp())){

            case 1:
                Resources res1 = mContext.getResources();
                Drawable img_off1 = res1.getDrawable(R.mipmap.ic_exp1);
                img_off1.setBounds(0, 0, img_off1.getMinimumWidth(), img_off1.getMinimumHeight());
                tv_username.setCompoundDrawables(null, null, img_off1, null); //设置右图标
                break;
            case 2:
                Resources res2 = mContext.getResources();
                Drawable img_off2 = res2.getDrawable(R.mipmap.ic_exp2);
                img_off2.setBounds(0, 0, img_off2.getMinimumWidth(), img_off2.getMinimumHeight());
                tv_username.setCompoundDrawables(null, null, img_off2, null); //设置右图标
                break;
            case 3:
                Resources res3 = mContext.getResources();
                Drawable img_off3 = res3.getDrawable(R.mipmap.ic_exp3);
                img_off3.setBounds(0, 0, img_off3.getMinimumWidth(), img_off3.getMinimumHeight());
                tv_username.setCompoundDrawables(null, null, img_off3, null); //设置右图标
                break;
            case 4:
                Resources res4 = mContext.getResources();
                Drawable img_off4 = res4.getDrawable(R.mipmap.ic_exp4);
                img_off4.setBounds(0, 0, img_off4.getMinimumWidth(), img_off4.getMinimumHeight());
                tv_username.setCompoundDrawables(null, null, img_off4, null); //设置右图标
                break;
            case 5:
                Resources res5 = mContext.getResources();
                Drawable img_off5 = res5.getDrawable(R.mipmap.ic_exp5);
                img_off5.setBounds(0, 0, img_off5.getMinimumWidth(), img_off5.getMinimumHeight());
                tv_username.setCompoundDrawables(null, null, img_off5, null); //设置右图标
                break;
            case 6:
                Resources res6 = mContext.getResources();
                Drawable img_off6 = res6.getDrawable(R.mipmap.ic_exp6);
                img_off6.setBounds(0, 0, img_off6.getMinimumWidth(), img_off6.getMinimumHeight());
                tv_username.setCompoundDrawables(null, null, img_off6, null); //设置右图标
                break;
        }
        if(!TextUtils.isEmpty(data.getIndustry())){
            tv_industry.setText(data.getIndustry());//行业
        }else{
            tv_industry.setText("暂无");//行业
        }
        if(!TextUtils.isEmpty(data.getBelongLabel())){
            tv_lable.setText(data.getBelongLabel());//归属标签
        }else{
            tv_lable.setText("暂无");//归属标签
        }
        StringBuffer sexoldaddress=new StringBuffer();
        if(!TextUtils.isEmpty(data.getSex())&&"0".equals(data.getSex())){
            sexoldaddress.append("男");//拼接性别
            sexoldaddress.append("\u3000");
        }else{
            sexoldaddress.append("女");//拼接性别
            sexoldaddress.append("\u3000");
        }
        if(!TextUtils.isEmpty(data.getBirthday())){
            sexoldaddress.append(StringToUtils.toOld(data.getBirthday()));
            sexoldaddress.append("\u3000");//岁数区间
        }
        if(!TextUtils.isEmpty(data.getHousingName())){
            sexoldaddress.append(data.getHousingName());
            sexoldaddress.append("\u3000");//小区名字
        }
        if(!TextUtils.isEmpty(sexoldaddress.toString())){
            tv_sexoldaddress.setText(sexoldaddress.toString());//性别年龄小区
        }else{
            tv_sexoldaddress.setText("暂无");//性别年龄小区
        }

        String userid= SharedPreferencesUtils.getString(Constant.SP_USERID);
        if(!TextUtils.isEmpty(data.getUserId())&&userid.equals(data.getUserId())){
            tv_addfriend.setVisibility(View.GONE);
        }else{
            tv_addfriend.setVisibility(View.VISIBLE);
        }
        //是否是好友是否是好友(0：不是好友，1:已经是好友，2：待同意)
        if(!TextUtils.isEmpty(data.getIsFriends())){
            if("0".equals(data.getIsFriends())){
                tv_addfriend.setText("加好友");
            }else if("1".equals(data.getIsFriends())){
                tv_addfriend.setText("已是好友");
            } else if("2".equals(data.getIsFriends())){
                tv_addfriend.setText("待同意");
            }
        }

        if(!TextUtils.isEmpty(data.getRemark())){
            tv_content.setText(data.getRemark());//内容
        }else{
            tv_content.setText("暂无内容");//内容
        }
        if(!TextUtils.isEmpty(data.getRemark())){
            tv_content.setText(data.getRemark());//内容
        }else{
            tv_content.setText("暂无内容");//内容
        }
        if(!TextUtils.isEmpty(data.getCommentCount())){
            String allStr="评论"+"("+data.getCommentCount()+")";
            SpannableStringBuilder builderCom = new SpannableStringBuilder(allStr);
            ForegroundColorSpan mSpanCom1 = new ForegroundColorSpan(getResources().getColor(R.color.black));
            ForegroundColorSpan mSpanCom = new ForegroundColorSpan(getResources().getColor(R.color.app_theme_color));
            builderCom.setSpan(mSpanCom1,0,2,Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            builderCom.setSpan(mSpanCom,2,allStr.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            tv_comment.setText(builderCom);//内容
        }else{
            String allStr="评论(0)";
            SpannableStringBuilder builderCom = new SpannableStringBuilder(allStr);
            ForegroundColorSpan mSpanCom = new ForegroundColorSpan(getResources().getColor(R.color.app_theme_color));
            builderCom.setSpan(mSpanCom,2,allStr.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            tv_comment.setText(builderCom);//内容
        }
        userListBeens.clear();
        if(data.getUserList()!=null&&data.getUserList().size()!=0){
            userListBeens.addAll(data.getUserList());
        }
        showUserListAdapter.notifyDataSetChanged();
        if (pageNo == 0) {
            showCommentdatas.clear();
        }
        if (data.getComment()==null||data.getComment().size() == 0) {
            if (pageNo == 0) {
                setLoadMoreText("暂无数据");
            } else {
                pageNo --;
                setLoadMoreText("没有更多了");
            }
        }
        if(data.getComment()!=null){
            showCommentdatas.addAll(data.getComment());
        }
        showCommentAdapter.notifyDataSetChanged();
    }
    @Override
    protected void pullDownRefresh() {
        super.pullDownRefresh();
        pageNo = 0;
        getData();
    }

    @Override
    protected void loadMore() {
        super.loadMore();
        pageNo++;
        getData();
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode==RESULT_OK){
            switch (requestCode){
                case 12:
                    showDialog();
                    pullDownRefresh();
                    break;
                case 3:
                    showDialog();
                    pullDownRefresh();
                    break;
            }

        }
    }
}
